import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'widgetPage/advancView.dart';
import 'widgetPage/pairingView.dart';


class SettingPage extends StatefulWidget {
  @override
  _SettingPageState createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
 
  var pageList = [PairingView(), AdvancView()];

  int currentSelect = 1;

  PageController _pageController;

  Widget settingBody() {
 
    return Container(
      color: Colors.grey[300],
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                color: Colors.white,
                child: ListView(
                  children: [
                    Container(
                      color: currentSelect == 1 ? Colors.green : Colors.white,
                      child: ListTile(
                        onTap: () {
                          setState(() {
                            this.currentSelect = 1;
                            _pageController.animateToPage(0, //跳转到的位置
                                duration: Duration(milliseconds: 16), //跳转的间隔时间
                                curve: Curves.fastOutSlowIn); //跳转动画)
                          });
                        },
                        leading: Icon(
                          Icons.shop,
                          color: Colors.amber,
                        ),
                        title: Text("基础设置"),
                        trailing: Icon(Icons.arrow_right),
                      ),
                    ),
                    Container(
                      color: currentSelect == 2 ? Colors.green : Colors.white,
                      child: ListTile(
                        onTap: () {
                          setState(() {
                            this.currentSelect = 2;
                            _pageController.animateToPage(1, //跳转到的位置
                                duration: Duration(milliseconds: 16), //跳转的间隔时间
                                curve: Curves.fastOutSlowIn); //跳转动画)
                          });
                        },
                        hoverColor: Colors.blue,
                        selected: true,
                        leading: Icon(
                          Icons.wifi,
                          color: Colors.amber,
                        ),
                        title: Text("高级设置"),
                        trailing: Icon(Icons.arrow_right),
                      ),
                    ),
                    Container(
                        color: currentSelect == 3 ? Colors.green : Colors.white,
                        child: ListTile(
                          onTap: () {
                            setState(() {});
                          },
                          leading: Icon(
                            Icons.more_horiz,
                            color: Colors.grey,
                          ),
                          title: Text("更多"),
                          trailing: Icon(Icons.arrow_right),
                        )),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
            flex: 2,
            child: Container(
                height: double.infinity,
                child: PageView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  onPageChanged: (index) {
                    print("当前");
                    print(index);
                  },
                  itemBuilder: (context, index) => Container(
                    child: pageList[index],
                  ),
                  itemCount: 10,
                  controller: _pageController,
                  //设置滑动方向
                  scrollDirection: Axis.vertical,
                )),
          ),
        ],
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    _pageController = PageController(
      initialPage: 0,
      viewportFraction: 1,
      keepPage: true,
    );
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
      SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
    return Scaffold(
     body: settingBody(),
    );
  }
}
